home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2002 November / SGI IRIX 6.5 Applications 2002 November.iso / dist / gateway.idb / usr / WebFace / Apps / sdr.cgi.z / sdr.cgi
Encoding:
Text File  |  2002-06-12  |  25.8 KB  |  796 lines

  1. #!/usr/bin/perl5
  2. #
  3. # sdr.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: sdr.cgi,v 1.19 1997/11/19 02:07:34 jrw Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23. require "/usr/OnRamp/lib/java.pm";
  24.  
  25. use POSIX;
  26.  
  27. $myname = "sdr.cgi";
  28. $list_script = "Apps.sdpd.cgi";
  29.  
  30. $file_dir = "$document_root/apps/sdpd-send";
  31.  
  32. $exp_date = "12-Dec-98";
  33.  
  34. @months = ('Jan','Feb','Mar','Apr','May','Jun',
  35.       'Jul','Aug','Sep','Oct','Nov','Dec');
  36. @days = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
  37.  
  38. if ($ARGV[0]) { 
  39.     $edit_file = $ARGV[0];
  40.     $fld{'mode'} = "e";
  41. } else { $fld{'mode'} = "a"; }
  42.  
  43. &get_cookies;
  44. &get_fields;
  45.  
  46. if ($fld{'get_id'}) {            # being called via "post" from sd-list.cgi
  47.     $new_id = time;
  48.  
  49.     $fld{'sdpd_email'} = $fld{'sdpd_email'};
  50.     if($fld{'sdpd_name'} ne "") { 
  51.         $fld{'sdpd_email'} .= " ($fld{'sdpd_name'})"; 
  52.     }
  53.     $fld{'sdpd_phone'} = $fld{'sdpd_phone'};
  54.  
  55.     $cookie_header = "Content-type: text/html\n"
  56.      . "Set-Cookie: sdpd_id=$new_id; expires=$exp_date; path=/\n"
  57.      . "Set-Cookie: sdpd_phone=$fld{'sdpd_phone'}; expires=$exp_date; path=/\n"
  58.      . "Set-Cookie: sdpd_email=$fld{'sdpd_email'}; expires=$exp_date; path=/\n\n";
  59.  
  60.     $set_cookie = 1;
  61. }
  62.  
  63. &set_timezone;
  64.  
  65. if ($edit_file) { &get_edit_values; }
  66. else { &get_initial_values; }
  67.  
  68. if ($fld{'submit'} eq 'Submit Announcement') {
  69.     $fld{'session_name'} =~ s/^\s+//g;
  70.         $fld{'session_name'} =~ s/\s+$//g;
  71.     if (!&form_validation) { 
  72.         &create_file;
  73.         $fld{'session_name'} =~ s/ /__/g;
  74.         $list_script .= "?$fld{'mode'}+$fld{'session_name'}";
  75.  
  76.         print "Content-type: text/html\n$update_cookie\n";
  77.         print "<HTML><HEAD>";
  78.         print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=$list_script\">";
  79.         print "</HEAD><BODY></BODY></HTML>";
  80.  
  81.         exit 0;
  82.     }
  83.     %val = %fld;
  84. }
  85.  
  86. &generic;
  87.  
  88. sub get_cookies {
  89.     local($a, $b);
  90.     undef %cookie;
  91.     foreach (split(/; /, $ENV{HTTP_COOKIE})) {
  92.         ($a, $b) = split(/=/, $_);
  93.         $a =~ s/\s//g;
  94.         $cookie{$a} = $b;
  95.     }
  96. }
  97.  
  98. sub form_validation {
  99.     if ($fld{'session_name'} eq "") {
  100.         $error = "Session name required."; 
  101.         return 1;
  102.     } elsif ($fld{'address'} eq "") {
  103.         $error = "Address required.";
  104.         return 1;
  105.     } elsif (check_ipaddr($fld{'address'})) {
  106.         $error = "Invalid IP address in \"Address\" field.";
  107.         return 1;
  108.     } 
  109.  
  110.     if ($fld{'audio_check'}) {
  111.         if (($error = &check_port($fld{'audio_port'})) ne "") { return 1; }
  112.     } elsif ($fld{'video_check'}) {
  113.         if (($error = &check_port($fld{'video_port'})) ne "") { return 1; }
  114.     } elsif ($fld{'white_check'}) {
  115.         if (($error = &check_port($fld{'white_port'})) ne "") { return 1; }
  116.     } elsif ($fld{'text_check'}) {
  117.         if (($error = &check_port($fld{'text_port'})) ne "") { return 1; }
  118.     }
  119.  
  120.     if ($fld{'email'} eq "" && $fld{'phone'} eq "") {
  121.         $error = "E-mail address or telephone number required.";
  122.         return 1;
  123.     }
  124. }
  125.  
  126. sub check_port {
  127.     if ($_[0] =~ /[^\d]/) { return "Port numbers must be integers."; }
  128.     elsif ($_[0] < 1024) { return "Port numbers must be more than 1023."; }
  129.     elsif ($_[0] > 65536) { return "Port numbers must be less tnan 65536."; }
  130.     "";
  131. }
  132.     
  133. sub create_file {
  134.  
  135.     if ($edit_file ne "") { $file = $edit_file; }
  136.     elsif ($fld{'edit_file'} ne "") { $file = $fld{'edit_file'}; }
  137.     else {
  138.         $file = tmpnam(0);
  139.         $file =~ /\/([^\/]*)$/;
  140.         $file = $file_dir . "/" . $1;
  141.     }
  142.  
  143.     foreach (keys(%months)) {
  144.         if ($months{$_} eq $cur_month) { $cur_month_num = $_; }
  145.     }
  146.     
  147.     ($s_hour, $s_min) = split(/:/,$fld{'time'});        
  148.     ($s_wday_nm, $s_mon_nm, $s_mday) = split(/\s+/,$fld{'date'});
  149.  
  150.     for ($i=0;$i<=$#months;$i++) {
  151.         if ($months[$i] eq $s_mon_nm) { $s_mon = $i; }
  152.     }
  153.  
  154.     if ($month_num < $cur_month_num) { $s_year = $c_year + 1; }
  155.     else { $s_year = $c_year; }
  156.  
  157.     $start_time = mktime(0,$s_min,$s_hour,$s_mday,$s_mon,$s_year,0,0,-1);
  158.     $start_time += 2208988800;
  159.  
  160.     if ($fld{'duration'} =~ /minutes/) { $dur_secs = 30 * 60; }
  161.     elsif ($fld{'duration'} =~ /(\d+) hour/) { $dur_secs = 3600 * $1; }
  162.     else { $dur_secs = 24 * 3600; }
  163.  
  164.     $rep_secs = 0;
  165.     if ($fld{'active'} ne "once") {    
  166.         if ($fld{'repeat'} =~ /(\d+) hour/) { $rep_secs = 3600 * $1; }
  167.         elsif ($fld{'repeat'} =~ /(\d+) day/) { $rep_secs = 24 * 3600 * $1; }
  168.         else { $fld{'repeat'} =~ /(\d+) week/; $rep_secs = 7 * 24 * 3600 * $1; }    
  169.  
  170.         if ($fld{'active'} eq 'daily') { $repeat_time = 24 * 3600; }
  171.         else { $repeat_time = 7 * 24 * 3600; }
  172.     }
  173.  
  174.     $finish_time = $start_time + $dur_secs + $rep_secs;
  175.                     
  176.     %ttl = ('site','15','region','63','world','127');
  177.  
  178.     if ($new_id) { $file_id = $new_id; }
  179.     else { $file_id = $cookie{'sdpd_id'}; }
  180.  
  181.     open(OUT,"> $file");
  182.  
  183.     print OUT qq|# $file_id\n#\n|;
  184.  
  185.     print OUT qq|vers2\n|;
  186.     print OUT qq|v=0\n|;
  187.  
  188.     if ($fld{'mode'} eq "a") { 
  189.         open(IN, "/usr/bin/whoami |");
  190.         $fld{'username'} = <IN>; chop($fld{'username'});
  191.         close(IN);
  192.         $fld{'session_id'} = time + 2208988800;
  193.         $fld{'version'} = $fld{'session_id'};
  194.  
  195.         open(IN, "/usr/OnRamp/bin/htnetwork |");
  196.         $my_line = <IN>;
  197.         close(IN);
  198.         $fld{'my_ip'} = (split(/:/,$my_line))[3];
  199.  
  200. #       @addrs = (gethostbyname($ENV{SERVER_NAME}))[4];
  201. #       $fld{'my_ip'} = join('.',unpack('C4', $addrs[0]));
  202.     }
  203.  
  204.     print OUT qq|o=$fld{'username'} $fld{'session_id'} $fld{'version'} IN IP4 $fld{'my_ip'}\n|;
  205.     
  206.     print OUT qq|s=$fld{'session_name'}\n|;
  207.  
  208.     $fld{'description'} =~ s/\r\n/ /g;
  209.     print OUT qq|i=$fld{'description'}\n|;
  210.     
  211.     if ($fld{'uri'}) { print OUT qq|u=$fld{'uri'}\n|; }
  212.     
  213.     print OUT qq|e=$fld{'email'}\n|;
  214.     print OUT qq|p=$fld{'phone'}\n|;
  215.  
  216.     print OUT qq|c=IN IP4 $fld{'address'}/$ttl{$fld{'ttl'}}\n|;
  217.  
  218.     print OUT qq|t=$start_time $finish_time\n|;
  219.  
  220.     if ($fld{'active'} ne "once") {
  221.         print OUT qq|r=$repeat_time $dur_secs 0\n|;
  222.     }
  223.  
  224.     if ($fld{'audio_check'}) {
  225.         print OUT qq|m=audio $fld{'audio_port'} $fld{'audio_protocol'}|,
  226.                   qq| $fld{'audio_format'}\n|;
  227.         if ($fld{'audio_recv'}) { print OUT qq|a=recvonly\n|; }    
  228.     }
  229.     if ($fld{'video_check'}) {
  230.         print OUT qq|m=video $fld{'video_port'} $fld{'video_protocol'}|,
  231.                   qq| $fld{'video_format'}\n|;
  232.         if ($fld{'video_recv'}) { print OUT qq|a=recvonly\n|; } 
  233.     }
  234.     if ($fld{'white_check'}) {
  235.         print OUT qq|m=white $fld{'white_port'} $fld{'white_protocol'}|,
  236.                   qq| $fld{'white_format'}\n|;
  237.         if ($fld{'white_recv'}) { print OUT qq|a=recvonly\n|; } 
  238.     }
  239.     if ($fld{'text_check'}) {
  240.         print OUT qq|m=text $fld{'text_port'} $fld{'text_protocol'}|,
  241.                   qq| $fld{'text_format'}\n|;
  242.         if ($fld{'text_recv'}) { print OUT qq|a=recvonly\n|; } 
  243.     }
  244.  
  245.     close(OUT);
  246.  
  247.     if ($fld{'email'} ne $cookie{'sdpd_email'}) {
  248.         $update_cookie = "Set-Cookie: sdpd_email=$fld{'email'};"
  249.                        . " expires=$exp_date; path=/\n"; 
  250.     }
  251.     if ($fld{'phone'} ne $cookie{'sdpd_phone'}) {
  252.         $update_cookie .= "Set-Cookie: sdpd_phone=$fld{'phone'};"
  253.                         . " expires=$exp_date; path=/\n"; 
  254.     }
  255. }
  256.     
  257. sub get_edit_values {
  258.  
  259.     open(IN, "< $edit_file");
  260.     
  261.     while(<IN>) {
  262.         @items = split(/=/);
  263.         chop($items[1]);
  264.  
  265.         if ($items[0] eq "o") { 
  266.         
  267.             ($fld{'username'}, $fld{'session_id'}, $fld{'version'}, 
  268.                 $dum, $dum, $fld{'my_ip'}) = split(/\s+/, $items[1]);
  269.     
  270.         } elsif ($items[0] eq "s") {
  271.             
  272.             $val{'session_name'} = $items[1];
  273.  
  274.         } elsif ($items[0] eq "i") {
  275.     
  276.             @words = split(/\s+/,$items[1]);
  277.  
  278.             $val{'description'} = shift(@words);
  279.             $len = length($val{'description'});
  280.  
  281.             while ($word = shift(@words)) {
  282.                 $len += length($word) + 1;
  283.  
  284.                 if ($len > 40) {
  285.                     $val{'description'} .= "\n$word";
  286.                     $len = length($word);
  287.                 } else { $val{'description'} .= " $word"; }
  288.             }
  289.  
  290.  
  291.         } elsif ($items[0] eq "u") {
  292.  
  293.             $val{'uri'} = $items[1];
  294.  
  295.         } elsif ($items[0] eq "e") {
  296.  
  297.             $val{'email'} = $items[1];
  298.  
  299.         } elsif ($items[0] eq "p") {
  300.  
  301.             $val{'phone'} = $items[1];
  302.  
  303.         } elsif ($items[0] eq "c") {
  304.  
  305.             ($val{'address'}, $ttl) = split(/\//, (split(/\s+/, $items[1]))[2]);
  306.             if    ($ttl == 15) { $val{'ttl'} = "site"; }
  307.             elsif ($ttl == 63) { $val{'ttl'} = "region"; }
  308.             else               { $val{'ttl'} = "world"; }
  309.  
  310.         } elsif ($items[0] eq "m") {
  311.  
  312.             ($format, $a, $b, $c) = split(/\s+/, $items[1]);
  313.             $val{$format . "_check"} = "on";
  314.             $val{$format . "_port"} = $a;
  315.             $val{$format . "_protocol"} = $b;
  316.             $val{$format . "_format"} = $c;
  317.  
  318.         } elsif ($items[0] eq "a") {
  319.  
  320.             $val{$format . "_recv"} = "on";
  321.  
  322.         } elsif ($items[0] eq "t") {
  323.  
  324.             ($start, $finish) = split(/\s+/, $items[1]);
  325.             $start -= 2208988800;
  326.             $finish -= 2208988800;
  327.             $time_diff = $finish - $start;
  328.  
  329.             ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($start);
  330.  
  331.             if ($min == 0) { $min = "00"; }
  332.             
  333.             $val{'date'} = "$days[$wday] $months[$mon] $mday";    
  334.             $val{'time'} = $hour . ":" . $min;
  335.         
  336.         } elsif ($items[0] eq "r") {
  337.  
  338.             ($rep_int, $act_dur, $dum) = split(/\s+/, $items[1]);
  339.             
  340.             if    ($act_dur < 3600) { $val{'duration'} = "30 minutes"; }
  341.             elsif ($act_dur < 7200) { $val{'duration'} = "1 hour"; }
  342.             elsif ($act_dur < 3600 * 11) { 
  343.                 $num_hours = $act_dur / 3600;
  344.                 $val{'duration'} = "$num_hours hours";
  345.             }
  346.             else { $val{'duration'} = "1 day"; }
  347.  
  348.             if ($rep_int == 3600 * 24) { $val{'active'} = "daily"; }
  349.             else { $val{'active'} = "weekly"; }
  350.  
  351.         }
  352.  
  353.     }
  354.  
  355.     close(IN);
  356.  
  357.     if ($rep_int) {
  358.  
  359.         $repeat = $time_diff - $act_dur;
  360.  
  361.         if ($repeat < 24 * 3600) { $type = "hour"; $num = $repeat / 3600; }
  362.         elsif ($repeat < 7 * 24 * 3600) { $type = "day";  $num = $repeat / (24 * 3600); }
  363.         else { $type = "week"; $num = $repeat / (7 * 24 * 3600); }
  364.  
  365.         if ($num != 1) { $plural = "s"; }
  366.  
  367.         $val{'repeat'} = "$num $type$plural";
  368.  
  369.     } else {
  370.  
  371.         $act_dur = $time_diff;
  372.         if    ($act_dur < 3600) { $val{'duration'} = "30 minutes"; }
  373.         elsif ($act_dur < 7200) { $val{'duration'} = "1 hour"; }
  374.         elsif ($act_dur < 3600 * 11) {
  375.             $num_hours = $act_dur / 3600;
  376.             $val{'duration'} = "$num_hours hours";
  377.         }
  378.         else { $val{'duration'} = "1 day"; }
  379.  
  380.     }
  381.  
  382.     $val{'edit_file'} = $edit_file;
  383. }        
  384.             
  385.         
  386. sub set_timezone {
  387.  
  388.     if (-e "/etc/TIMEZONE") { 
  389.         open(IN,"< /etc/TIMEZONE");    
  390.         while(<IN>) {
  391.             @items = split(/=/);
  392.             if ($items[0] eq "TZ") { 
  393.                 chop $items[1]; 
  394.                 $ENV{'TZ'} = $items[1]; 
  395.             }
  396.         }
  397.         close(IN);
  398.     }
  399. }
  400.  
  401. sub get_initial_values {
  402.  
  403.     ($c_sec, $c_min, $c_hour, $c_mday, $c_mon, $c_year, $c_wday, $c_yday,
  404.         $c_isdst) = localtime(time);
  405.  
  406.     $val{'time'} = $c_hour . ":00";
  407.  
  408.     if ($c_mon < 2) { $leap_check = $c_year; }
  409.     else { $leap_check = $c_year + 1; }
  410.  
  411.     $leap_check = 0;
  412.     if ( ($leap_check % 4) == 0 && ($leap_check % 100) != 0 ) { $leap_year = 1; }
  413.     if ($leap_year) { $feb_days = 29; }
  414.     else { $feb_days = 28; }
  415.  
  416.     $val{'date'} = "$days[$c_wday] $months[$c_mon] $c_mday";
  417.  
  418.     srand(time);
  419.  
  420.     $val{'audio_port'} = int(rand(65535-5001)) + 5001;
  421.     $val{'video_port'} = int(rand(65535-5001)) + 5001;
  422.     $val{'white_port'} = int(rand(65535-5001)) + 5001;
  423.     $val{'text_port' } = int(rand(65535-5001)) + 5001;
  424.  
  425.     $ip_3 = int(rand(253)) + 1;
  426.     $ip_4 = int(rand(253)) + 1;
  427.  
  428.     $val{'address'} = "224.2." . $ip_3 . "." . $ip_4;
  429.  
  430.     if ($fld{'get_id'}) {
  431.         $val{'phone'} = $fld{'sdpd_phone'};
  432.         $val{'email'} = $fld{'sdpd_email'};
  433.     } else {
  434.         $val{'phone'} = $cookie{'sdpd_phone'};
  435.         $val{'email'} = $cookie{'sdpd_email'};
  436.     }
  437.  
  438.     $val{'audio_check'} = "on";
  439. }
  440.  
  441. sub generic {
  442.  
  443.     if ($set_cookie) { print $cookie_header; }
  444.     else { print qq|Content-type: text/html\n\n|; }
  445.     print qq|<html><head><title>Session Directory Manager</title>\n|;
  446.  
  447.     &print_javascript;
  448.  
  449.     print qq|</head>\n|;
  450.  
  451.     print "<body bgcolor=#CCC28F background=\"/images/sdr-bg.gif\"\n";
  452.     print "link=#00582A vlink=#27002B>\n";
  453.  
  454.     print "<table width=100%>\n";
  455.     print "<tr><th align=left><h1>Create Announcement</h1></th>\n";
  456.     print "<th align=right>\n";
  457.     print "<a href=\"/apps/sdr_hlp.cgi\"><img border=0 height=65 width=30 src=\"/images/help.gif\"></a>\n";
  458.     print "  ";
  459.     print "<a href=\"/newsplash.shtml\"><img border=0 height=55 width=57 src=\"/apps/home.gif\"></a>\n";
  460.         print "  ";
  461.         print "<a href=\"/apps/Apps.shtml\"><img border=0 height=55 width=57 src=\"/apps/back.gif\"></a>\n";
  462.     print "</tr></table>\n";
  463.  
  464.     print qq|<map name="time_map">\n|; 
  465.     print qq|<area shape="rect" coords="0,0,15,15" href="JavaScript:TimeUp()">|;
  466.     print qq|<area shape="rect" coords="0,15,15,30" href="JavaScript:TimeDown()">|;
  467.     print qq|</map>|;
  468.  
  469.     print qq|<map name="date_map">\n|;
  470.     print qq|<area shape="rect" coords="0,0,15,15" href="JavaScript:DateUp()">|;
  471.     print qq|<area shape="rect" coords="0,15,15,30" href="JavaScript:DateDown()">|;
  472.     print qq|</map>|;
  473.  
  474.     print qq|<center>\n|;
  475.  
  476.     print qq|</center><i>$message</i><center>\n|;
  477.     if ($error) {print qq|</center><font color=#FF0000>Error: $error</font><center>\n|; }
  478.  
  479.     print qq|<form name="page1" method=post action=$myname onSubmit="return runSubmit()">\n|;
  480.  
  481.     print qq|<input type="hidden" name="mode" value=$fld{'mode'}>\n|;
  482.  
  483.     if ($val{'edit_file'}) {
  484.         print qq|<input type="hidden" name="session_id" value=$fld{'session_id'}>\n|;
  485.         print qq|<input type="hidden" name="version" value=$fld{'version'}>\n|;
  486.         print qq|<input type="hidden" name="my_ip" value=$fld{'my_ip'}>\n|;
  487.         print qq|<input type="hidden" name="username" value=$fld{'username'}>\n|;
  488.         print qq|<input type="hidden" name="edit_file" value=$val{'edit_file'}>\n|; 
  489.     }
  490.  
  491.     print qq|<input type="hidden" name="feb_days" value="$feb_days">\n|;
  492.  
  493.     print qq|<table width=600>\n|;
  494.  
  495.     print qq|<tr><th align=left>Session Name:</th><td align=left>\n|, 
  496.           &mtext("session_name", $val{'session_name'}, 30), "</td></tr>\n";
  497.  
  498.     print qq|<tr><th align=left valign=top>Description:</th><td align=left>\n|,
  499.           qq|<textarea name="description" rows=5 cols=40>$val{'description'}|,
  500.           qq|</textarea></td></tr>|;
  501.  
  502.     print qq|<tr><th align=left>Reference URL:</th><td align=left>\n|,
  503.           &text("uri", $val{'uri'}, 30), "</td></tr>\n";
  504.         
  505.     print qq|<tr align=left><th>Address:</th><td align=left>\n|, 
  506.           &text("address", $val{'address'}, 30), "</td></tr>\n";
  507.  
  508.     print qq|<tr><th align=left>Scope (ttl):</th><td align=left>\n|,
  509.           &select("ttl",$val{'ttl'},"site","region","world"), "</td></tr>\n";
  510.  
  511.     print qq|</table><hr><table width=600>\n|;
  512.  
  513.     print qq|<tr><th align=left colspan=2>Media</th><th align=left>Recvonly</th>|,
  514.           qq|<th align=left>Protocol</th><th align=left>Format</th><th align=left>|,
  515.           qq|Port</th></tr>\n|;
  516.  
  517.     print qq|<tr><td>|, &check("audio_check", $val{'audio_check'}), 
  518.           qq|</td><th align=left>Audio</th>|;
  519.     print qq|<td>|, &check("audio_recv", $val{'audio_recv'}), qq|</td>|;
  520.     print qq|<td>|, &select("audio_protocol", $val{'audio_protocol'},"vat","rtp"), 
  521.           qq|</td>\n|;
  522.     print qq|<td>|, &select("audio_format", $val{'audio_format'},"pcm","dvi","gsm","lpc4"), 
  523.           qq|</td>\n|;
  524.     print qq|<td>|, &text("audio_port", $val{'audio_port'}, 6), qq|</td>\n|; 
  525.     print qq|</tr>|;
  526.     
  527.     print qq|<tr><td>|, &check("video_check", $val{'video_check'}), 
  528.           qq|</td><th align=left>Video</th>|;
  529.     print qq|<td>|, &check("video_recv", $val{'video_recv'}), qq|</td>|;
  530.     print qq|<td>|, &select("video_protocol", $val{'video_protocol'},"rtp"), qq|</td>\n|;
  531.     print qq|<td>|, &select("video_format", $val{'video_format'},"nv","h261","jpg","ivs"), 
  532.           qq|</td>\n|;
  533.     print qq|<td>|, &text("video_port", $val{'video_port'}, 6), qq|</td>\n|; 
  534.     print qq|</tr>|;
  535.     
  536.     print qq|<tr><td>|, &check("white_check", $val{'white_check'}), 
  537.           qq|</td><th align=left>Whiteboard</th>|;
  538.     print qq|<td>|, &check("white_recv", $val{'white_recv'}), qq|</td>|;
  539.     print qq|<td>|, &select("white_protocol", $val{'white_protocol'},"udp"), qq|</td>\n|;
  540.     print qq|<td>|, &select("white_format", $val{'white_format'},"wb","nt"), qq|</td>\n|;
  541.     print qq|<td>|, &text("white_port", $val{'white_port'}, 6), qq|</td>\n|; 
  542.     print qq|</tr>|;
  543.     
  544.     print qq|<tr><td>|, &check("text_check", $val{'text_check'}), qq|</td><th align=left>Text</th>|;
  545.     print qq|<td>|, &check("text_recv", $val{'text_recv'}), qq|</td>|;
  546.     print qq|<td>|, &select("text_protocol", $val{'text_protocol'},"udp"), qq|</td>\n|;
  547.     print qq|<td>|, &select("text_format", $val{'text_format'},"nt","mumble"), qq|</td>\n|;
  548.     print qq|<td>|, &text("text_port", $val{'text_port'}, 6), qq|</td>\n|; 
  549.     print qq|</tr>|;
  550.     
  551.     print qq|</table><hr><table width=600>|;
  552.  
  553.     print qq|<tr><th align=left>Broadcast</th><td align=left>\n|;
  554.     print &select("active",$val{'active'},"once","daily","weekly"), "</td></tr>\n";
  555.     print "<tr><th align=left>From:</th><td align=left>", 
  556.           qq|<input type="text" name="date" value="$val{'date'}" size=10 onFocus="this.blur();">\n|,
  557.           qq|<img src="/images/arrows.gif" border=2 align="top" usemap="#date_map">\n|,
  558.           qq|<input type="text" name="time" value="$val{'time'}" size=5 onFocus="this.blur();">\n|, 
  559.           qq|<img src="/images/arrows.gif" border=2 align="top" usemap="#time_map">\n|,
  560.           qq| for |,    
  561.           &select("duration",$val{'duration'},"30 minutes","1 hour","2 hours","3 hours",
  562.           "4 hours","5 hours","6 hours","7 hours","8 hours","9 hours",
  563.           "10 hours","1 day"), "</td></tr>\n";
  564.     print qq|<tr><th align=left>Repeat for:</th><td align=left>\n|,
  565.           &select("repeat",$val{'repeat'},"1 hour","2 hours","3 hours","4 hours",
  566.           "5 hours","6 hours","7 hours","8 hours","9 hours","10 hours",
  567.           "1 day","2 days","3 days","4 days","5 days","1 week","2 weeks",
  568.           "3 weeks","4 weeks"),
  569.           qq|</td></tr>\n|;
  570.  
  571.     print qq|</table><hr><table width=600>\n|;
  572.  
  573.     print qq|<tr><th align=left>Email:</th><td>|,
  574.           qq|<input type=text name="email" value="$val{'email'}" size=30></td></tr>\n|;
  575.  
  576.     print qq|<tr><th align=left>Phone:</th><td>|,
  577.           qq|<input type=text name="phone" value="$val{'phone'}" size=30></td></tr>\n|;
  578.  
  579.     print qq|</table><table width=600 cellpadding=20>\n|;
  580.     
  581.     print qq|<tr><td align=center><input name="submit" type="submit" |,
  582.           qq|value="Submit Announcement"> <input type="reset" |,
  583.           qq|value="Reset Original Values"</td></tr>\n|;
  584.  
  585.     print qq|</table>\n|;
  586.  
  587.     print qq|</center></form></body></html>\n|;
  588.  
  589. }
  590.  
  591. sub mtext { 
  592.     local($ret) = "<input name=\"$_[0]\" value=\"$_[1]\"";
  593.     if ($_[2]) { $ret .= " size=$_[2]"; }
  594.     $ret .= ">";
  595. }
  596.  
  597. sub check {
  598.     local($ret) = qq|<input type=checkbox name=$_[0]|;
  599.     if ($_[1]) { $ret .= " checked"; }
  600.     $ret .= ">";
  601. }
  602.  
  603. sub print_javascript {
  604.  
  605. print <<EOJS
  606.  
  607. <script language="JavaScript">
  608. <!--
  609.  
  610. function TimeUp() 
  611. {
  612.     var hours, minutes;
  613.     form = document.page1;
  614.     hours = form.time.value.substring(0,2);
  615.     minutes = form.time.value.substring(3,5);
  616.     if (minutes == "30") {
  617.         hours = eval(hours + "+1");
  618.         if (hours < 10) { hours = "0" + hours; }
  619.         if (hours > 23) { hours = "00"; }
  620.         minutes = "00";
  621.     } else {
  622.         minutes = "30";
  623.     }
  624.     form.time.value = hours + ":" + minutes; 
  625. }
  626.  
  627. function TimeDown()
  628. {
  629.     var hours, minutes;
  630.     form = document.page1;
  631.     hours = form.time.value.substring(0,2);
  632.     minutes = form.time.value.substring(3,5);
  633.     if (minutes == "30") {
  634.         minutes = "00";
  635.     } else {
  636.         hours = eval(hours + "-1");
  637.         if (hours < 0) { hours = "23"; }
  638.         if (hours < 10) { hours = "0" + hours; }
  639.         minutes = "30";
  640.     }
  641.     form.time.value = hours + ":" + minutes;       
  642. }
  643.  
  644. function DateUp()
  645. {
  646.     days_in_month = new createArray(12);
  647.     days_of_week = new createArray(7);
  648.     mon_yr = new createArray(12);
  649.     var j, week_day, week_day_nm, num_day, month;
  650.     var add_month;
  651.  
  652.     form = document.page1;
  653.  
  654.     mon_yr[0] = "Jan"; mon_yr[1] = "Feb"; mon_yr[2] = "Mar"; mon_yr[3] = "Apr";
  655.     mon_yr[4] = "May"; mon_yr[5] = "Jun"; mon_yr[6] = "Jul"; mon_yr[7] = "Aug";
  656.     mon_yr[8] = "Sep"; mon_yr[9] = "Oct"; mon_yr[10] = "Nov"; mon_yr[11] = "Dec";
  657.     
  658.     for (j=0; j<12; j++) { days_in_month[j] = 31; }
  659.     days_in_month[1] = form.feb_days.value;
  660.     days_in_month[3] = 30;
  661.     days_in_month[5] = 30;
  662.     days_in_month[8] = 30;
  663.     days_in_month[10] = 30;
  664.  
  665.     days_of_week[0] = "Sun"; days_of_week[1] = "Mon"; days_of_week[2] = "Tue"; days_of_week[3] = "Wed";
  666.     days_of_week[4] = "Thu"; days_of_week[5] = "Fri"; days_of_week[6] = "Sat";
  667.  
  668.     week_day = form.date.value.substring(0,3);
  669.     num_day = form.date.value.substring(8,10);
  670.     month = form.date.value.substring(4,7);
  671.  
  672.     for (j=0; j<7; j++) { 
  673.         if (week_day == days_of_week[j]) { week_day_nm = j; }
  674.     }
  675.     week_day_nm = eval(week_day_nm + "+1");
  676.     if (week_day_nm > 6) { week_day = "Sun"; }
  677.     else { week_day = days_of_week[week_day_nm]; }
  678.  
  679.     for (j=0; j<12; j++) {
  680.         if (month == mon_yr[j]) { month_nm = j; }
  681.     }
  682.     add_month = 0;
  683.     if (num_day == days_in_month[month_nm]) {
  684.         num_day = 1;
  685.         add_month = 1;
  686.     } else { num_day = eval(num_day + "+1"); }
  687.     if (add_month == 1) {
  688.         month_nm = eval(month_nm + "+1");
  689.         if (month_nm == 12) { month_nm = 1; }
  690.         month = mon_yr[month_nm];
  691.     }
  692.  
  693.     form.date.value = week_day + " " + month + " " + num_day;
  694.  
  695. function DateDown()
  696. {
  697.     days_in_month = new createArray(12);
  698.     days_of_week = new createArray(7);
  699.     mon_yr = new createArray(12);
  700.     var j, week_day, week_day_nm, num_day, month;
  701.  
  702.     form = document.page1;
  703.     mon_yr[0] = "Jan"; mon_yr[1] = "Feb"; mon_yr[2] = "Mar"; mon_yr[3] = "Apr";
  704.     mon_yr[4] = "May"; mon_yr[5] = "Jun"; mon_yr[6] = "Jul"; mon_yr[7] = "Aug";
  705.     mon_yr[8] = "Sep"; mon_yr[9] = "Oct"; mon_yr[10] = "Nov"; mon_yr[11] = "Dec";
  706.  
  707.     for (j=0; j<12; j++) { days_in_month[j] = 31; }
  708.     days_in_month[1] = form.feb_days.value;
  709.     days_in_month[3] = 30;
  710.     days_in_month[5] = 30;
  711.     days_in_month[8] = 30;
  712.     days_in_month[10] = 30;
  713.  
  714.     days_of_week[0] = "Sun"; days_of_week[1] = "Mon"; days_of_week[2] = "Tue"; days_of_week[3] = "Wed";
  715.     days_of_week[4] = "Thu"; days_of_week[5] = "Fri"; days_of_week[6] = "Sat";
  716.  
  717.     week_day = form.date.value.substring(0,3);
  718.     num_day = form.date.value.substring(8,10);
  719.     month = form.date.value.substring(4,7);
  720.     for (j=0; j<7; j++) {
  721.         if (week_day == days_of_week[j]) { week_day_nm = j; }
  722.     }
  723.  
  724.     week_day_nm = eval(week_day_nm + "-1");
  725.     if (week_day_nm < 0) { week_day = "Sat"; }
  726.     else { week_day = days_of_week[week_day_nm]; }
  727.     for (j=0; j<12; j++) {
  728.         if (month == mon_yr[j]) { month_nm = j; }
  729.     }
  730.  
  731.     num_day = eval(num_day + "-1");
  732.     if (num_day < 1) {
  733.         month_nm = eval(month_nm + "-1");
  734.         if (month_nm < 0) { month_nm = 11; }
  735.         num_day = days_in_month[month_nm];
  736.         month = mon_yr[month_nm];
  737.     }
  738.     
  739.     form.date.value = week_day + " " + month + " " + num_day;
  740. }
  741.  
  742. function createArray(num) {
  743.     this.length = 12;
  744.     for (var j=0; j < num; j++) { this[j] = ""; }
  745. }
  746.  
  747. function runSubmit() {
  748.     form = document.page1; 
  749.     if(form.session_name.value == "") { 
  750.         errorBox (form.session_name, "A session name is required."); return (false); 
  751.     }
  752.     if(form.address.value == "") { 
  753.         errorBox (form.address, "An IP address is required."); return (false); 
  754.     }
  755.     if(!testIPaddress(form.address.value)) { 
  756.         errorBox (form.address, "IP address is invalid."); return (false); 
  757.     }
  758.     if(form.audio_check.checked && !checkPort(form.audio_port, "An audio")) { return (false); }
  759.     if(form.video_check.checked && !checkPort(form.video_port, "A video")) { return (false); }
  760.     if(form.text_check.checked && !checkPort(form.text_port, "A text")) { return (false); }
  761.     if(form.white_check.checked && !checkPort(form.white_port, "A whiteboard")) { return (false); }
  762.     if(form.phone.value == "" && form.email.value == "") { 
  763.         errorBox (form.phone, "Either an email address or a \\nphone number is required."); return (false); 
  764.     }
  765.     return (true);
  766. }
  767.  
  768. function checkPort(Ctrl, type) {
  769.     if (Ctrl.value == "") {
  770.         errorBox (Ctrl, type + " port number is required."); 
  771.         return (false); 
  772.     }
  773.     if (! checkInt(Ctrl.value, 10)) {
  774.         errorBox (Ctrl, "Port numbers must be integers."); return (false); 
  775.     }
  776.     if (Ctrl.value < 1024) {
  777.         errorBox (Ctrl, "Port numbers must be at least 1024."); return (false); 
  778.     }
  779.     if (Ctrl.value > 65536) {
  780.         errorBox (Ctrl, "Port numbers must be less than 65536"); return (false); 
  781.     }
  782.     return (true);
  783. }
  784.  
  785. $js_ip
  786. $js_error_box 
  787.  
  788.  
  789. // -->
  790. </script>
  791.  
  792. EOJS
  793.  
  794. }
  795.